﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO_MechSys;
using BLL_MechSys;

namespace FORMS_MechSys
{
    public partial class frmServicosPendentes : Form
    {
        #region Variaveis
        DataTable dataTableGridView = new DataTable();
        List<DTOOrdemPendente> ListOrdemPendente = new List<DTOOrdemPendente>();

        DTOCliente dtoCliente = new DTOCliente();
        //DTOOrdemPendente dtoOrdemPendente = new DTOOrdemPendente();
        DTOOrdemDetalheServico dtoOrdemDetalheServico = new DTOOrdemDetalheServico();
        //DTOOrdemDetalheProduto dtoOrdemDetalheProduto = new DTOOrdemDetalheProduto();
        DTOCor dtoCorPrincipal = new DTOCor();
        DTOCor dtoCorFundo = new DTOCor();
        DTOCor dtoCorLetra = new DTOCor();
        DTOCor dtoCorDataGrid = new DTOCor();

        
        
        BLLOrdemPendente bllOrdemPendente = new BLLOrdemPendente();
        BLLCliente bllCliente = new BLLCliente();
        BLLCor bllCor = new BLLCor();

        #endregion


        #region Metodos
        public frmServicosPendentes()
        {
            InitializeComponent();
            SetColors();
            this.WindowState = FormWindowState.Maximized;
            PopularGridServicos();
        }

        private void SetColors()
        {
            dtoCorPrincipal = bllCor.Buscar("Principal");

            btnConcluirServico.BackColor = tlpVeiculo.BackColor =
                lbl1.BackColor = btn_pesquisar.BackColor = btnEditarServico.BackColor =
                tlpDetalhesInterno.BackColor = statusStrip1.BackColor =
                toolStrip1.BackColor = tlpPesquisa.BackColor =
                btnExcluirServico.BackColor = dtoCorPrincipal.Cor;


            dtoCorFundo = bllCor.Buscar("Fundo");
            tlpPrincipal.BackColor = dtoCorFundo.Cor;

            dtoCorDataGrid = bllCor.Buscar("DataGrid");
            dgvServicos.BackgroundColor = dtoCorDataGrid.Cor;

            dtoCorLetra = bllCor.Buscar("Letra");
            btnConcluirServico.ForeColor =
                label4.ForeColor = lblstatus.ForeColor =
                lbl1.ForeColor = btnExcluirServico.ForeColor =
                btnEditarServico.ForeColor = dtoCorLetra.Cor;


        }

        public void Limpar()
        {
            txtPesquisar.Clear();
            dgvServicos.DataSource = null;
        }

        public void PopularGridServicos()
        {
            dgvServicos.DataSource = new BLLServico().BuscarServicosPendentes();

        }
        #endregion

        #region Eventos

        #region Click

        private void toolStripButtonSair_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnEditarServico_Click(object sender, EventArgs e)
        {
            timerCarrosNaOficina.Enabled = true;
            dgvServicos_CellClick(null, null);
            if (!dtoOrdemDetalheServico.Status)
            {
                new frmServicoAdicionar(dtoOrdemDetalheServico).ShowDialog();
                PopularGridServicos();
            }
            else
                new frmMessageBox().Show("O serviço já está Concluído e não pode ser Editado");
            timerCarrosNaOficina.Enabled = false;
        }
        private void btnConcluirServico_Click(object sender, EventArgs e)
        {
            timerCarrosNaOficina.Enabled = true;
            dgvServicos_CellClick(null, null);
            dtoOrdemDetalheServico.Status = true;
            new BLLOrdemDetalheServico().Atualizar(dtoOrdemDetalheServico);
            PopularGridServicos();
            new frmMessageBox().Show("Servico Concluído", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
            timerCarrosNaOficina.Enabled = false;
        }
        private void btnExcluirServico_Click(object sender, EventArgs e)
        {
            timerCarrosNaOficina.Enabled = true;
            dgvServicos.Focus();
            if (dgvServicos.Rows.Count > 0)
            {
                if (dgvServicos.CurrentCellAddress.Y != -1)
                {
                    if (new frmMessageBox().Show("Tem certeza que deseja Remover este Serviço Pendente?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
                    {
                        new BLLOrdemDetalheServico().Excluir(Int32.Parse(dgvServicos["OrdemDetalheServicoID", dgvServicos.CurrentCellAddress.Y].Value.ToString()));
                        PopularGridServicos();
                    }
                }
                else
                    new frmMessageBox().Show("Selecione um produto no Grid");

                dgvServicos.Focus();
            }

            timerCarrosNaOficina.Enabled = false;
        }

        private void btn_pesquisar_Click(object sender, EventArgs e)
        {
            int cod = new int();
            Int32.TryParse(txtPesquisar.Text, out cod);
            //popular grid pesquisa
        }
        #endregion

        #region EnabledChanged
        private void btnEditarServico_EnabledChanged(object sender, EventArgs e)
        {
            if (btnEditarServico.Enabled)
            {
                btnEditarServico.BackColor = dtoCorPrincipal.Cor;
                btnEditarServico.ForeColor = dtoCorLetra.Cor;
            }
            else
                btnEditarServico.BackColor = dtoCorFundo.Cor;

        }
        private void btnExcluirServico_EnabledChanged(object sender, EventArgs e)
        {
            if (btnExcluirServico.Enabled)
            {
                btnExcluirServico.BackColor = dtoCorPrincipal.Cor;
                btnExcluirServico.ForeColor = dtoCorLetra.Cor;
            }
            else
                btnExcluirServico.BackColor = dtoCorFundo.Cor;

        }
        private void btnConcluirServico_EnabledChanged(object sender, EventArgs e)
        {
            if (btnConcluirServico.Enabled)
            {
                btnConcluirServico.BackColor = dtoCorPrincipal.Cor;
                btnConcluirServico.ForeColor = dtoCorLetra.Cor;
            }
            else
                btnConcluirServico.BackColor = dtoCorFundo.Cor;

        }

        #endregion

        #region Mouse Enter
        private void btnConcluirServicokkkkkkk(object sender, EventArgs e)
        {
            btnConcluirServico.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(224)))), ((int)(((byte)(255)))));
            btnConcluirServico.ForeColor = Color.Black;

        }
        private void btnExcluirServicokkkkkkk(object sender, EventArgs e)
        {
            btnExcluirServico.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(224)))), ((int)(((byte)(255)))));
            btnExcluirServico.ForeColor = Color.Black;

        }
        private void btnEditarServicokkkkkkk(object sender, EventArgs e)
        {
            btnEditarServico.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(224)))), ((int)(((byte)(255)))));
            btnEditarServico.ForeColor = Color.Black;

        }
        private void btnConcluirServicokkkkkkk_1(object sender, EventArgs e)
        {
            btnConcluirServico.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(224)))), ((int)(((byte)(255)))));
            btnConcluirServico.ForeColor = Color.Black;
        }
        private void btn_pesquisarkkkkkkk(object sender, EventArgs e)
        {

            btn_pesquisar.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(224)))), ((int)(((byte)(255)))));
            btn_pesquisar.ForeColor = Color.Black;
        }
        #endregion

        #region Mouse Leave
        private void btn_pesquisar_MouseLeave(object sender, EventArgs e)
        {
            if (btn_pesquisar.Enabled)
            {
                btn_pesquisar.BackColor = dtoCorPrincipal.Cor;
                btn_pesquisar.ForeColor = dtoCorLetra.Cor;
            }

        }
        private void btnEditarServico_MouseLeave(object sender, EventArgs e)
        {
            if (btnEditarServico.Enabled)
            {
                btnEditarServico.BackColor = dtoCorPrincipal.Cor;
                btnEditarServico.ForeColor = dtoCorLetra.Cor;
            }
        }
        private void btnExcluirServico_MouseLeave(object sender, EventArgs e)
        {
            if (btnExcluirServico.Enabled)
            {
                btnExcluirServico.BackColor = dtoCorPrincipal.Cor;
                btnExcluirServico.ForeColor = dtoCorLetra.Cor;
            }
        }
        private void btnConcluirServico_MouseLeave(object sender, EventArgs e)
        {
            if (btnConcluirServico.Enabled)
            {
                btnConcluirServico.BackColor = dtoCorPrincipal.Cor;
                btnConcluirServico.ForeColor = dtoCorLetra.Cor;
            }
        }
        #endregion

        #region Grid
        private void dgvServicos_DataSourceChanged(object sender, EventArgs e)
        {

            if (dgvServicos.RowCount > 0)
            {
                dgvServicos.Columns["OrdemDetalheServicoID"].Visible = false;
                btnConcluirServico.Enabled = true;
                btnEditarServico.Enabled = true;
                btnExcluirServico.Enabled = true;
            }
            else
            {
                btnConcluirServico.Enabled = false;
                btnEditarServico.Enabled = false;
                btnExcluirServico.Enabled = false;
            }
        }
        private void dgvServicos_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgvServicos.Rows.Count > 0)
            {
                if (dgvServicos.CurrentCellAddress.Y != -1)
                {
                    int ordemDetalheServicoID =
                    Int32.Parse(dgvServicos["OrdemDetalheServicoID", dgvServicos.CurrentCellAddress.Y].Value.ToString());
                    dtoOrdemDetalheServico = new BLLOrdemDetalheServico().Buscar(ordemDetalheServicoID);
                }
                else
                    new frmMessageBox().Show("Selecione um produto no Grid");

            }
        }
        #endregion

        #region Outros
        private void timer_Tick(object sender, EventArgs e)
        {
            PopularGridServicos();
        }
        private void txtPesquisar_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btn_pesquisar_Click(null, null);
        }
        #endregion




        #endregion
    }
}